package cn.kgc.fxy.smbms.web;

import cn.kgc.fxy.smbms.entity.User;
import cn.kgc.fxy.smbms.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
@RequestMapping("/pwd")
public class PwdController {
    @Resource
    private UserService userService;

    @RequestMapping("/toModif")
    public String toModif(){
        return "pwd/pwdmodify";
    }
    @RequestMapping("/modify")
    public String modify(Long userId,String oldpassword,String newpassword){
        System.out.println("newpassword新= " + oldpassword);
        System.out.println("userId = " + userId);
        User user = userService.findByUserPassword(userId);
        String laoPassword = user.getUserPassword();
        System.out.println("laoPassword老 = " + laoPassword);
        if (laoPassword.equals(oldpassword)){
            userService.modifyPwd(newpassword,userId);

            return "login";
        }

        return "pwd/pwdmodify";
    }
}
